$(function(){
	$.ajax({
		type: "POST",
		url: "/BookStore/order.do?method=2",
		dataType: "json",
		success: function(data){
			if(data != null) {
				var array = $('#address');
				
			}
			for(var i = 0;i < data.address.length; i ++){
				array.append('<option value='+JSON.stringify(data.address[i])+'>'+i+':'+data.address[i].receiveName+'</option>');
			}
		}
	});
	
	$('#address').change(function(){
		var value = $(this).children('option:selected').val();
		if(value == -1){
			$('input[name=add]').val(-1);
			$('#receiveName').val('');
			$('#fullAddress').val('');
			$('#postalCode').val('');
			$('#phone').val('');
			$('#mobile').val('');
		} else {
			json = JSON.parse(value);
			$('input[name=add]').val(json.id);
			$('#receiveName').val(json.receiveName);
			$('#fullAddress').val(json.fullAddress);
			$('#postalCode').val(json.postalCode);
			$('#phone').val(json.phone);
			$('#mobile').val(json.mobile);
		}
	});
});